package obj;

import game.GameWin;
import utils.GameUtils;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class PlaneObj extends GameObj {
    //血量
    int life = 10;
    //防御值(3为最高防御值）
    public static int defend = 3;

    @Override
    public Image getImage() {
        return super.getImage();
    }

    public PlaneObj() {
        super();
    }

    public PlaneObj(Image image, int x, int y, double speed) {
        super(image, x, y, speed);
    }

    public PlaneObj(Image image, int x, int y, int width, int height, double speed, GameWin frame) {
        super(image, x, y, width, height, speed, frame);
        this.frame.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                PlaneObj.super.x = e.getX() - 11;
                PlaneObj.super.y = e.getY() - 16;
            }
        });
    }

    @Override
    public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);

        for (BulletObj bulletObj : GameUtils.bulletObjList) {
            if (this.getRec().intersects(bulletObj.getRec())) {
                bulletObj.setX(-100);
                bulletObj.setY(100);
                GameUtils.removeList.add(bulletObj);
                life = life - 1;
            }
            if (life <= 0) {
                GameWin.state = 4;
            }
        }
        //血条标签
        GameUtils.drawWord(gImage, "我方飞机血量值：", Color.yellow, 20, 20, 190);
        //血条的白色背景
        gImage.setColor(Color.white);
        gImage.fillRect(20, 200, 150, 10);
        //血条的绘制
        gImage.setColor(Color.red);
        gImage.fillRect(20, 200, life * 150 / 10, 10);

        if (this.frame.bossObj != null && this.getRec().intersects(this.frame.bossObj.getRec())) {
            GameWin.state = 3;
        }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
